package com.ruoyi.web.controller.pc;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.TRobot;
import com.ruoyi.system.domain.vo.PCLoginVo;
import com.ruoyi.system.domain.vo.PcLoginSearchVo;
import com.ruoyi.system.dto.PcLoginListDTO;
import com.ruoyi.system.service.IPCService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/pc/user")
public class PcController extends BaseController {
    @Autowired
    private IPCService pcService;
    /**
     * 手机号是否有PC端登录权限
     */
    @ApiOperation(value = "手机号是否有PC端登录权限")
    @GetMapping(value = "/pcLoginCheck/{phone}")
    @Anonymous
    public AjaxResult pcLoginCheck(@PathVariable("phone") String phone)
    {
        return success(pcService.pcLoginCheck(phone));
    }

    /**
     * 新增PC端权限
     */
    @ApiOperation(value = "新增PC端权限")
    @PostMapping(value = "/add/pcLogin")
    public AjaxResult addPcLogin(@RequestBody PCLoginVo loginVo)
    {
        return success(pcService.addPcLogin(loginVo));
    }

    /**
     * PC端权限用户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PcLoginSearchVo searchVo)
    {
        startPage();
        List<PcLoginListDTO> list = pcService.selectPcLoginList(searchVo);
        // 获取准确的总数
        int total = pcService.countList(searchVo);

        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(200);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(total);

        return rspData;
    }

    /**
     * 删除PC端权限用户
     */
    @GetMapping("/del/{id}")
    public Boolean del(@PathVariable Integer id)
    {
        return pcService.del(id);
    }

}
